import {
    CategoryWithChildren,
    ColSpanInfo,
    CreateSpeciesStatisticsParams,
    ReportGenerateResult,
    ReportParagraphBlock,
    RowSpanInfo,
    TableGenerateResult,
} from "./typings/index";
import {
    extractSpeciesStatisticsTotalCategory,
    generateSpeciesStatistics,
    getProportionValue,
    generateWordParagraBlockByPlainText,
    generateWordParagraBlockByTableGenerateResult,
    extractNationalProtectionSpeciesStatisticsTotalCategory
} from "./utils";

//计算一个Category中科属种占比统计
const caculateCategoryLevelProportionTable = () => {

}

//计算一个Category中科属种数量统计
const caculateCategoryLevelCountTable = () => {

}

//计算一个Category中各科占比
const caculateCategoryFamilyProportionTable = (
    speciesCategory: CategoryWithChildren
): TableGenerateResult => {
    let tableResult: TableGenerateResult = {
        tableStyle: 'normalTable'
    };
    let tableData: string[][] = [
        ["科名", "属", "", "种", ""],
        ["", "数量", "占比%", "数量", "占比%"],
    ];
    let totalGenusCount = extractSpeciesStatisticsTotalCategory(speciesCategory, 'genus');
    let totalSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesCategory, 'species');
    for (const orderKey in speciesCategory) {
        const orderRecord = speciesCategory[orderKey].children;
        for (const familyKey in orderRecord) {
            let totalGenusCountForTheFamily = 0;
            let totalSpeciesCountForTheFamily = 0;
            const familyRecord = orderRecord[familyKey].children;
            const familyLatin = orderRecord[familyKey].latin;
            for (const genusKey in familyRecord) {
                totalGenusCountForTheFamily++;
                const genusRecord = familyRecord[genusKey].children;
                for (const speciesKey in genusRecord) {
                    totalSpeciesCountForTheFamily++;
                }
            }
            let tempTableRow = [
                `${familyKey} ${familyLatin}`,
                totalGenusCountForTheFamily.toString(),
                getProportionValue(totalGenusCountForTheFamily, totalGenusCount),
                totalSpeciesCountForTheFamily.toString(),
                getProportionValue(totalSpeciesCountForTheFamily, totalSpeciesCount)
            ];
            tableData.push(tempTableRow);
        }
    }
    let tableRowSpanInfoList: RowSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 0,
            rowSpan: 2
        }
    ];
    let tableColSpanInfoList: ColSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 1,
            colSpan: 2
        },
        {
            rowIndex: 0,
            colIndex: 3,
            colSpan: 2
        }
    ];
    tableData.push(["总计", "", "100", "", "100"]);
    tableResult.tableData = tableData;
    tableResult.tableRowSpanInfoList = tableRowSpanInfoList;
    tableResult.tableColSpanInfoList = tableColSpanInfoList;
    return tableResult;
}


//计算一个Category中科与属的数量结构
const caculateCategoryFamilyAndGenusQuantitativeStructure = (
    speciesCategory: CategoryWithChildren
): TableGenerateResult => {
    let tableResult: TableGenerateResult = {
        tableStyle: 'normalTable',
        tableHeaderRowNumber: 2,
    };
    let tableData: string[][] = [
        ["类别", "科", "", "属", ""],
        ["", "数量", "占比%", "数量", "占比%"],
    ];
    let totalFamilyCount = extractSpeciesStatisticsTotalCategory(speciesCategory, 'family');
    let totalGenusCount = extractSpeciesStatisticsTotalCategory(speciesCategory, 'genus');
    let familyStructureList: { familyName: string, genusCount: number }[] = [];
    for (const orderKey in speciesCategory) {
        const orderRecord = speciesCategory[orderKey].children;
        for (const familyKey in orderRecord) {
            let totalGenusCountForTheFamily = 0;
            const familyRecord = orderRecord[familyKey].children;
            for (const genusKey in familyRecord) {
                totalGenusCountForTheFamily++;
            }
            familyStructureList.push({
                familyName: familyKey,
                genusCount: totalGenusCountForTheFamily
            })
        }
    }
    // console.log("familyStructureList--->", familyStructureList)
    let moreThan20GenusOfFamilyTotalCount = 0;  //超过20个属的科总数
    let moreThan20GenusOfGenusTotalCount = 0;   //超过20个属的属总数
    // 
    let between11_19GenusOfFamilyTotalCount = 0;  //超过11～19个属的科总数
    let between11_19GenusOfGenusTotalCount = 0;   //超过11～19个属的属总数
    // 
    let between5_10GenusOfFamilyTotalCount = 0;  //超过5～10个属的科总数
    let between5_10GenusOfGenusTotalCount = 0;   //超过5～10个属的属总数
    // 
    let between2_4GenusOfFamilyTotalCount = 0;  //超过2～4个属的科总数
    let between2_4GenusOfGenusTotalCount = 0;   //超过2～4个属的属总数
    // 
    let singleGenusOfFamilyTotalCount = 0;  //超过20个属的科总数
    let singleGenusOfGenusTotalCount = 0;   //超过20个属的属总数
    familyStructureList.forEach((familyStructure, index) => {
        if (familyStructure.genusCount == 1) {
            singleGenusOfFamilyTotalCount++;
            singleGenusOfGenusTotalCount += familyStructure.genusCount;
        } else if (
            familyStructure.genusCount >= 2 &&
            familyStructure.genusCount <= 4
        ) {
            between2_4GenusOfFamilyTotalCount++;
            between2_4GenusOfGenusTotalCount += familyStructure.genusCount;
        } else if (
            familyStructure.genusCount >= 5 &&
            familyStructure.genusCount <= 10
        ) {
            between5_10GenusOfFamilyTotalCount++;
            between5_10GenusOfGenusTotalCount += familyStructure.genusCount;
        } else if (
            familyStructure.genusCount >= 11 &&
            familyStructure.genusCount <= 19
        ) {
            between11_19GenusOfFamilyTotalCount++;
            between11_19GenusOfGenusTotalCount += familyStructure.genusCount;
        } else if (
            familyStructure.genusCount >= 20
        ) {
            moreThan20GenusOfFamilyTotalCount++;
            moreThan20GenusOfGenusTotalCount += familyStructure.genusCount;
        }
    })
    let tableDataRow1 = [
        "含20属以上",
        moreThan20GenusOfFamilyTotalCount.toString(),
        getProportionValue(moreThan20GenusOfFamilyTotalCount, totalFamilyCount),
        moreThan20GenusOfGenusTotalCount.toString(),
        getProportionValue(moreThan20GenusOfGenusTotalCount, totalGenusCount),
    ];
    let tableDataRow2 = [
        "含11～19属",
        between11_19GenusOfFamilyTotalCount.toString(),
        getProportionValue(between11_19GenusOfFamilyTotalCount, totalFamilyCount),
        between11_19GenusOfGenusTotalCount.toString(),
        getProportionValue(between11_19GenusOfGenusTotalCount, totalGenusCount),
    ];
    let tableDataRow3 = [
        "含5～10属",
        between5_10GenusOfFamilyTotalCount.toString(),
        getProportionValue(between5_10GenusOfFamilyTotalCount, totalFamilyCount),
        between5_10GenusOfGenusTotalCount.toString(),
        getProportionValue(between5_10GenusOfGenusTotalCount, totalGenusCount),
    ];
    let tableDataRow4 = [
        "含2～4属",
        between2_4GenusOfFamilyTotalCount.toString(),
        getProportionValue(between2_4GenusOfFamilyTotalCount, totalFamilyCount),
        between2_4GenusOfGenusTotalCount.toString(),
        getProportionValue(between2_4GenusOfGenusTotalCount, totalGenusCount),
    ];
    let tableDataRow5 = [
        "单属科",
        singleGenusOfFamilyTotalCount.toString(),
        getProportionValue(singleGenusOfFamilyTotalCount, totalFamilyCount),
        singleGenusOfGenusTotalCount.toString(),
        getProportionValue(singleGenusOfGenusTotalCount, totalGenusCount),
    ];
    let tableDataRow6 = [
        "合计",
        totalFamilyCount.toString(),
        '100',
        totalGenusCount.toString(),
        '100',
    ];
    let tableRowSpanInfoList: RowSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 0,
            rowSpan: 2
        }
    ];
    let tableColSpanInfoList: ColSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 1,
            colSpan: 2
        },
        {
            rowIndex: 0,
            colIndex: 3,
            colSpan: 2
        }
    ];
    tableData.push(tableDataRow1);
    tableData.push(tableDataRow2);
    tableData.push(tableDataRow3);
    tableData.push(tableDataRow4);
    tableData.push(tableDataRow5);
    tableData.push(tableDataRow6);
    tableResult.tableData = tableData;
    tableResult.tableRowSpanInfoList = tableRowSpanInfoList;
    tableResult.tableColSpanInfoList = tableColSpanInfoList;
    return tableResult;
}

//计算一个Category中科与种的数量结构
const caculateCategoryFamilyAndSpeciesQuantitativeStructure = (
    speciesCategory: CategoryWithChildren
): TableGenerateResult => {
    let tableResult: TableGenerateResult = {
        tableStyle: 'normalTable',
        tableHeaderRowNumber: 2,
    };
    let tableData: string[][] = [
        ["类别", "科", "", "种", ""],
        ["", "数量", "占比%", "数量", "占比%"],
    ];
    let totalFamilyCount = extractSpeciesStatisticsTotalCategory(speciesCategory, 'family');
    let totalSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesCategory, 'species');
    let familyStructureList: { familyName: string, speciesCount: number }[] = [];
    for (const orderKey in speciesCategory) {
        const orderRecord = speciesCategory[orderKey].children;
        for (const familyKey in orderRecord) {
            let totalSpeciesCountForTheFamily = 0;
            const familyRecord = orderRecord[familyKey].children;
            for (const genusKey in familyRecord) {
                const genusRecord = familyRecord[genusKey].children;
                for (const speciesKey in genusRecord) {
                    totalSpeciesCountForTheFamily++;
                }
            }
            familyStructureList.push({
                familyName: familyKey,
                speciesCount: totalSpeciesCountForTheFamily
            })
        }
    }
    // console.log("familyStructureList--->", familyStructureList)
    let moreThan50SpeciesOfFamilyTotalCount = 0;  //超过20个属的科总数
    let moreThan50SpeciesOfSpeciesTotalCount = 0;   //超过20个属的属总数
    // 
    let between20_49SpeciesOfFamilyTotalCount = 0;  //超过11～19个属的科总数
    let between20_49SpeciesOfSpeciesTotalCount = 0;   //超过11～19个属的属总数
    // 
    let between10_19SpeciesOfFamilyTotalCount = 0;  //超过5～10个属的科总数
    let between10_19SpeciesOfSpeciesTotalCount = 0;   //超过5～10个属的属总数
    // 
    let between2_9SpeciesOfFamilyTotalCount = 0;  //超过2～4个属的科总数
    let between2_9SpeciesOfSpeciesTotalCount = 0;   //超过2～4个属的属总数
    // 
    let singleSpeciesOfFamilyTotalCount = 0;  //超过20个属的科总数
    let singleSpeciesOfSpeciesTotalCount = 0;   //超过20个属的属总数
    familyStructureList.forEach((familyStructure, index) => {
        if (familyStructure.speciesCount === 1) {
            singleSpeciesOfFamilyTotalCount++;
            singleSpeciesOfSpeciesTotalCount += familyStructure.speciesCount;
        } else if (
            familyStructure.speciesCount >= 2 &&
            familyStructure.speciesCount <= 9
        ) {
            between2_9SpeciesOfFamilyTotalCount++;
            between2_9SpeciesOfSpeciesTotalCount += familyStructure.speciesCount;
        } else if (
            familyStructure.speciesCount >= 10 &&
            familyStructure.speciesCount <= 19
        ) {
            between10_19SpeciesOfFamilyTotalCount++;
            between10_19SpeciesOfSpeciesTotalCount += familyStructure.speciesCount;
        } else if (
            familyStructure.speciesCount >= 20 &&
            familyStructure.speciesCount <= 49
        ) {
            between20_49SpeciesOfFamilyTotalCount++;
            between20_49SpeciesOfSpeciesTotalCount += familyStructure.speciesCount;
        } else if (
            familyStructure.speciesCount >= 50
        ) {
            moreThan50SpeciesOfFamilyTotalCount++;
            moreThan50SpeciesOfSpeciesTotalCount += familyStructure.speciesCount;
        }
    })
    let tableDataRow1 = [
        "含50种以上",
        moreThan50SpeciesOfFamilyTotalCount.toString(),
        getProportionValue(moreThan50SpeciesOfFamilyTotalCount, totalFamilyCount),
        moreThan50SpeciesOfSpeciesTotalCount.toString(),
        getProportionValue(moreThan50SpeciesOfSpeciesTotalCount, totalSpeciesCount),
    ];
    let tableDataRow2 = [
        "含20～49种",
        between20_49SpeciesOfFamilyTotalCount.toString(),
        getProportionValue(between20_49SpeciesOfFamilyTotalCount, totalFamilyCount),
        between20_49SpeciesOfSpeciesTotalCount.toString(),
        getProportionValue(between20_49SpeciesOfSpeciesTotalCount, totalSpeciesCount),
    ];
    let tableDataRow3 = [
        "含10～19种",
        between10_19SpeciesOfFamilyTotalCount.toString(),
        getProportionValue(between10_19SpeciesOfFamilyTotalCount, totalFamilyCount),
        between10_19SpeciesOfSpeciesTotalCount.toString(),
        getProportionValue(between10_19SpeciesOfSpeciesTotalCount, totalSpeciesCount),
    ];
    let tableDataRow4 = [
        "含2～9种",
        between2_9SpeciesOfFamilyTotalCount.toString(),
        getProportionValue(between2_9SpeciesOfFamilyTotalCount, totalFamilyCount),
        between2_9SpeciesOfSpeciesTotalCount.toString(),
        getProportionValue(between2_9SpeciesOfSpeciesTotalCount, totalSpeciesCount),
    ];
    let tableDataRow5 = [
        "单种科",
        singleSpeciesOfFamilyTotalCount.toString(),
        getProportionValue(singleSpeciesOfFamilyTotalCount, totalFamilyCount),
        singleSpeciesOfSpeciesTotalCount.toString(),
        getProportionValue(singleSpeciesOfSpeciesTotalCount, totalSpeciesCount),
    ];
    let tableDataRow6 = [
        "合计",
        totalFamilyCount.toString(),
        '100',
        totalSpeciesCount.toString(),
        '100',
    ];
    let tableRowSpanInfoList: RowSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 0,
            rowSpan: 2
        }
    ];
    let tableColSpanInfoList: ColSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 1,
            colSpan: 2
        },
        {
            rowIndex: 0,
            colIndex: 3,
            colSpan: 2
        }
    ];
    tableData.push(tableDataRow1);
    tableData.push(tableDataRow2);
    tableData.push(tableDataRow3);
    tableData.push(tableDataRow4);
    tableData.push(tableDataRow5);
    tableData.push(tableDataRow6);
    tableResult.tableData = tableData;
    tableResult.tableRowSpanInfoList = tableRowSpanInfoList;
    tableResult.tableColSpanInfoList = tableColSpanInfoList;
    return tableResult;
}

//计算一个Category中各属占比
const caculateCategoryGenusProportionTable = (
    speciesCategory: CategoryWithChildren
): TableGenerateResult => {
    let tableResult: TableGenerateResult = {
        tableStyle: 'genusCollectTable',
        tableHeaderRowNumber: 2,
    };
    let tableData: string[][] = [
        ["属名", "种", ""],
        ["", "数量", "占比%"],
    ];
    let totalSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesCategory, 'species');
    for (const orderKey in speciesCategory) {
        const orderRecord = speciesCategory[orderKey].children;
        for (const familyKey in orderRecord) {
            const familyRecord = orderRecord[familyKey].children;
            for (const genusKey in familyRecord) {
                let totalSpeciesCountForTheGenus = 0;
                const genusLatin = familyRecord[genusKey].latin
                const genusRecord = familyRecord[genusKey].children;
                for (const speciesKey in genusRecord) {
                    totalSpeciesCountForTheGenus++;
                }
                let tableRowData = [
                    `${genusKey} ${genusLatin}`,
                    totalSpeciesCountForTheGenus.toString(),
                    getProportionValue(totalSpeciesCountForTheGenus, totalSpeciesCount)
                ];
                tableData.push(tableRowData);
            }
        }
    }
    let tableRowSpanInfoList: RowSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 0,
            rowSpan: 2
        }
    ];
    let tableColSpanInfoList: ColSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 1,
            colSpan: 2
        },
    ];
    tableData.push(["总计", "", "100"]);
    tableResult.tableData = tableData;
    tableResult.tableRowSpanInfoList = tableRowSpanInfoList;
    tableResult.tableColSpanInfoList = tableColSpanInfoList;
    return tableResult;
}

//计算一个Category中属与种的数量结构
const caculateCategoryGenusAndSpeciesQuantitativeStructure = (
    speciesCategory: CategoryWithChildren
): TableGenerateResult => {
    let tableResult: TableGenerateResult = {
        tableStyle: 'genusCollectTable',
        tableHeaderRowNumber: 2,
    };
    let tableData: string[][] = [
        ["类别", "属", "", "种", ""],
        ["", "数量", "占比%", "数量", "占比%"],
    ];
    let totalGenusCount = extractSpeciesStatisticsTotalCategory(speciesCategory, 'genus');
    let totalSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesCategory, 'species');
    let genusStructureList: { genusName: string, speciesCount: number }[] = [];
    for (const orderKey in speciesCategory) {
        const orderRecord = speciesCategory[orderKey].children;
        for (const familyKey in orderRecord) {
            const familyRecord = orderRecord[familyKey].children;
            for (const genusKey in familyRecord) {
                let totalSpeciesCountForTheFamily = 0;
                const genusRecord = familyRecord[genusKey].children;
                for (const speciesKey in genusRecord) {
                    totalSpeciesCountForTheFamily++;
                }
                genusStructureList.push({
                    genusName: genusKey,
                    speciesCount: totalSpeciesCountForTheFamily
                })
            }
        }
    }
    let moreThan20SpeciesOfGenusTotalCount = 0;  //超过20个种的属总数
    let moreThan20SpeciesOfSpeciesTotalCount = 0;   //超过20个种的种总数
    // 
    let between11_19SpeciesOfGenusTotalCount = 0;  //超过11～19个种的属总数
    let between11_19SpeciesOfSpeciesTotalCount = 0;   //超过11～19个种的种总数
    // 
    let between5_10SpeciesOfGenusTotalCount = 0;  //超过5～10个种的属总数
    let between5_10SpeciesOfSpeciesTotalCount = 0;   //超过5～10个种的种总数
    // 
    let between2_4SpeciesOfGenusTotalCount = 0;  //超过2～4个种的属总数
    let between2_4SpeciesOfSpeciesTotalCount = 0;   //超过2～4个种的种总数
    // 
    let singleSpeciesOfGenusTotalCount = 0;  //单个种的属总数
    let singleSpeciesOfSpeciesTotalCount = 0;   //单个种的种总数
    genusStructureList.forEach((genusStructure, index) => {
        if (genusStructure.speciesCount == 1) {
            singleSpeciesOfGenusTotalCount++;
            singleSpeciesOfSpeciesTotalCount += genusStructure.speciesCount;
        } else if (
            genusStructure.speciesCount >= 2 &&
            genusStructure.speciesCount <= 4
        ) {
            between2_4SpeciesOfGenusTotalCount++;
            between2_4SpeciesOfSpeciesTotalCount += genusStructure.speciesCount;
        } else if (
            genusStructure.speciesCount >= 5 &&
            genusStructure.speciesCount <= 10
        ) {
            between5_10SpeciesOfGenusTotalCount++;
            between5_10SpeciesOfSpeciesTotalCount += genusStructure.speciesCount;
        } else if (
            genusStructure.speciesCount >= 11 &&
            genusStructure.speciesCount <= 19
        ) {
            between11_19SpeciesOfGenusTotalCount++;
            between11_19SpeciesOfSpeciesTotalCount += genusStructure.speciesCount;
        } else if (
            genusStructure.speciesCount >= 20
        ) {
            moreThan20SpeciesOfGenusTotalCount++;
            moreThan20SpeciesOfSpeciesTotalCount += genusStructure.speciesCount;
        }
    });
    let tableDataRow1 = [
        "含20种以上",
        moreThan20SpeciesOfGenusTotalCount.toString(),
        getProportionValue(moreThan20SpeciesOfGenusTotalCount, totalGenusCount),
        moreThan20SpeciesOfSpeciesTotalCount.toString(),
        getProportionValue(moreThan20SpeciesOfSpeciesTotalCount, totalSpeciesCount),
    ];
    let tableDataRow2 = [
        "含11～19种",
        between11_19SpeciesOfGenusTotalCount.toString(),
        getProportionValue(between11_19SpeciesOfGenusTotalCount, totalGenusCount),
        between11_19SpeciesOfSpeciesTotalCount.toString(),
        getProportionValue(between11_19SpeciesOfSpeciesTotalCount, totalSpeciesCount),
    ];
    let tableDataRow3 = [
        "含5～10种",
        between5_10SpeciesOfGenusTotalCount.toString(),
        getProportionValue(between5_10SpeciesOfGenusTotalCount, totalGenusCount),
        between5_10SpeciesOfSpeciesTotalCount.toString(),
        getProportionValue(between5_10SpeciesOfSpeciesTotalCount, totalSpeciesCount),
    ];
    let tableDataRow4 = [
        "含2～4种",
        between2_4SpeciesOfGenusTotalCount.toString(),
        getProportionValue(between2_4SpeciesOfGenusTotalCount, totalGenusCount),
        between2_4SpeciesOfSpeciesTotalCount.toString(),
        getProportionValue(between2_4SpeciesOfSpeciesTotalCount, totalSpeciesCount),
    ];
    let tableDataRow5 = [
        "单种属",
        singleSpeciesOfGenusTotalCount.toString(),
        getProportionValue(singleSpeciesOfGenusTotalCount, totalGenusCount),
        singleSpeciesOfSpeciesTotalCount.toString(),
        getProportionValue(singleSpeciesOfSpeciesTotalCount, totalSpeciesCount),
    ];
    let tableDataRow6 = [
        "合计",
        totalGenusCount.toString(),
        '100',
        totalSpeciesCount.toString(),
        '100',
    ];
    let tableRowSpanInfoList: RowSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 0,
            rowSpan: 2
        }
    ];
    let tableColSpanInfoList: ColSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 1,
            colSpan: 2
        },
        {
            rowIndex: 0,
            colIndex: 3,
            colSpan: 2
        },
    ];
    tableData.push(tableDataRow1);
    tableData.push(tableDataRow2);
    tableData.push(tableDataRow3);
    tableData.push(tableDataRow4);
    tableData.push(tableDataRow5);
    tableData.push(tableDataRow6);
    tableResult.tableData = tableData;
    tableResult.tableRowSpanInfoList = tableRowSpanInfoList;
    tableResult.tableColSpanInfoList = tableColSpanInfoList;
    return tableResult;
}

//计算保护植物科属种占比统计表
const caculateProtectionPlantCategoryLevelProportionTable = (
    speciesCategory1: CategoryWithChildren,
    speciesCategory2: CategoryWithChildren,
    speciesCategory3: CategoryWithChildren
): ReportParagraphBlock => {

    let colSpanInfoList: ColSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 2,
            colSpan: 2,
        },
        {
            rowIndex: 0,
            colIndex: 4,
            colSpan: 2,
        },
        {
            rowIndex: 0,
            colIndex: 6,
            colSpan: 2,
        },
    ];
    let rowSpanInfoList: RowSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 0,
            rowSpan: 2,
        },
        {
            rowIndex: 0,
            colIndex: 1,
            rowSpan: 2,
        },
    ];
    let tableData: string[][] = [
        ["分类", "保护等级", "科", "", "属", "", "种", ""],
        ["", "", "数量", "占比%", "数量", "占比%", "数量", "占比%"],
    ];
    let rowSpanStartRowIndex = 2;
    //被子植物
    const result1 = extractNationalProtectionSpeciesStatisticsTotalCategory(speciesCategory1);
    //裸子植物
    const result2 = extractNationalProtectionSpeciesStatisticsTotalCategory(speciesCategory2);
    //蕨类植物
    const result3 = extractNationalProtectionSpeciesStatisticsTotalCategory(speciesCategory3);
    //总物种数量
    const totalSpeciesCount =
        result1.uniquenSpeciesNameList1.length + result1.uniquenSpeciesNameList2.length +
        result2.uniquenSpeciesNameList1.length + result2.uniquenSpeciesNameList2.length +
        result3.uniquenSpeciesNameList1.length + result3.uniquenSpeciesNameList2.length
    //总科数量
    const totalGenusCount =
        result1.uniquenGenusNameList1.length + result1.uniquenGenusNameList2.length +
        result2.uniquenGenusNameList1.length + result2.uniquenGenusNameList2.length +
        result3.uniquenGenusNameList1.length + result3.uniquenGenusNameList2.length
    //
    const totalFamilyCount =
        result1.uniquenFamilyNameList1.length + result1.uniquenFamilyNameList2.length +
        result2.uniquenFamilyNameList1.length + result2.uniquenFamilyNameList2.length +
        result3.uniquenFamilyNameList1.length + result3.uniquenFamilyNameList2.length
    const totalOrderCount =
        result1.uniquenOrderNameList1.length + result1.uniquenOrderNameList2.length +
        result2.uniquenOrderNameList1.length + result2.uniquenOrderNameList2.length +
        result3.uniquenOrderNameList1.length + result3.uniquenOrderNameList2.length
    //统计被子植物
    if (speciesCategory1) {
        rowSpanInfoList.push({
            rowIndex: rowSpanStartRowIndex,
            colIndex: 0,
            rowSpan: 3,
        })
        tableData.push([
            "被子植物",
            "国家I级",
            `${result1.uniquenFamilyNameList1.length}`,
            `${getProportionValue(result1.uniquenFamilyNameList1.length, totalFamilyCount)}`,
            `${result1.uniquenGenusNameList1.length}`,
            `${getProportionValue(result1.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${result1.uniquenSpeciesNameList1.length}`,
            `${getProportionValue(result1.uniquenSpeciesNameList1.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "国家II级",
            `${result1.uniquenFamilyNameList2.length}`,
            `${getProportionValue(result1.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${result1.uniquenGenusNameList2.length}`,
            `${getProportionValue(result1.uniquenGenusNameList2.length, totalGenusCount)}`,
            `${result1.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(result1.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "小记",
            `${result1.uniquenFamilyNameList1.length + result1.uniquenFamilyNameList2.length}`,
            `${getProportionValue(result1.uniquenFamilyNameList1.length + result1.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${result1.uniquenGenusNameList1.length + result1.uniquenGenusNameList2.length}`,
            `${getProportionValue(result1.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${result1.uniquenSpeciesNameList1.length + result1.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(result1.uniquenSpeciesNameList1.length + result1.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        rowSpanStartRowIndex += 3;
    }
    //
    if (speciesCategory1) {
        rowSpanInfoList.push({
            rowIndex: rowSpanStartRowIndex,
            colIndex: 0,
            rowSpan: 3,
        })
        tableData.push([
            "裸子植物",
            "国家I级",
            `${result2.uniquenFamilyNameList1.length}`,
            `${getProportionValue(result2.uniquenFamilyNameList1.length, totalFamilyCount)}`,
            `${result2.uniquenGenusNameList1.length}`,
            `${getProportionValue(result2.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${result2.uniquenSpeciesNameList1.length}`,
            `${getProportionValue(result2.uniquenSpeciesNameList1.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "国家II级",
            `${result2.uniquenFamilyNameList2.length}`,
            `${getProportionValue(result2.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${result2.uniquenGenusNameList2.length}`,
            `${getProportionValue(result2.uniquenGenusNameList2.length, totalGenusCount)}`,
            `${result2.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(result2.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "小记",
            `${result2.uniquenFamilyNameList1.length + result2.uniquenFamilyNameList2.length}`,
            `${getProportionValue(result1.uniquenFamilyNameList1.length + result2.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${result2.uniquenGenusNameList1.length + result2.uniquenGenusNameList2.length}`,
            `${getProportionValue(result2.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${result2.uniquenSpeciesNameList1.length + result2.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(result2.uniquenSpeciesNameList1.length + result2.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        rowSpanStartRowIndex += 3;
    }
    //
    if (speciesCategory3) {
        rowSpanInfoList.push({
            rowIndex: rowSpanStartRowIndex,
            colIndex: 0,
            rowSpan: 3,
        })
        tableData.push([
            "蕨类植物",
            "国家I级",
            `${result3.uniquenFamilyNameList1.length}`,
            `${getProportionValue(result3.uniquenFamilyNameList1.length, totalFamilyCount)}`,
            `${result3.uniquenGenusNameList1.length}`,
            `${getProportionValue(result3.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${result3.uniquenSpeciesNameList1.length}`,
            `${getProportionValue(result3.uniquenSpeciesNameList1.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "国家II级",
            `${result3.uniquenFamilyNameList2.length}`,
            `${getProportionValue(result3.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${result3.uniquenGenusNameList2.length}`,
            `${getProportionValue(result3.uniquenGenusNameList2.length, totalGenusCount)}`,
            `${result3.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(result3.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "小记",
            `${result3.uniquenFamilyNameList1.length + result3.uniquenFamilyNameList2.length}`,
            `${getProportionValue(result3.uniquenFamilyNameList1.length + result3.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${result3.uniquenGenusNameList1.length + result3.uniquenGenusNameList2.length}`,
            `${getProportionValue(result3.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${result3.uniquenSpeciesNameList1.length + result3.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(result3.uniquenSpeciesNameList1.length + result3.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        rowSpanStartRowIndex += 3;
    }
    tableData.push([
        "总记",
        "总记",
        `${totalFamilyCount}`,
        `100`,
        `${totalGenusCount}`,
        `100`,
        `${totalSpeciesCount}`,
        `100`,
    ])
    colSpanInfoList.push({
        rowIndex: tableData.length - 1,
        colIndex: 0,
        colSpan: 2,
    })
    let paragraph: ReportParagraphBlock = {
        type: "Table",
        text: "表格",
        tableData: tableData,
        colSpanInfoList: colSpanInfoList,
        rowSpanInfoList: rowSpanInfoList,
        tableHeaderRowNumber: 1,
    }
    return paragraph;
}

//计算保护大型真菌科属种数量统计表
const caculateProtectionFungusCategoryLevelCountTable = (
    speciesCategory: CategoryWithChildren,
): ReportParagraphBlock => {
    let colSpanInfoList: ColSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 2,
            colSpan: 2,
        },
        {
            rowIndex: 0,
            colIndex: 4,
            colSpan: 2,
        },
        {
            rowIndex: 0,
            colIndex: 6,
            colSpan: 2,
        },
    ];
    let rowSpanInfoList: RowSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 0,
            rowSpan: 2,
        },
    ];
    let tableData: string[][] = [
        ["保护等级", "科", "科", "属", "属", "种", "种"],
        ["", "数量", "占比%", "数量", "占比%", "数量", "占比%"],
    ];
    const result1 = extractNationalProtectionSpeciesStatisticsTotalCategory(speciesCategory);
    //总物种数量
    const totalSpeciesCount =
        result1.uniquenSpeciesNameList1.length + result1.uniquenSpeciesNameList2.length;
    //总科数量
    const totalGenusCount =
        result1.uniquenGenusNameList1.length + result1.uniquenGenusNameList2.length;
    //
    const totalFamilyCount =
        result1.uniquenFamilyNameList1.length + result1.uniquenFamilyNameList2.length;
    if (speciesCategory) {
        tableData.push([
            "国家I级",
            `${result1.uniquenFamilyNameList1.length}`,
            `${getProportionValue(result1.uniquenFamilyNameList1.length, totalFamilyCount)}`,
            `${result1.uniquenGenusNameList1.length}`,
            `${getProportionValue(result1.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${result1.uniquenSpeciesNameList1.length}`,
            `${getProportionValue(result1.uniquenSpeciesNameList1.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "国家II级",
            `${result1.uniquenFamilyNameList2.length}`,
            `${getProportionValue(result1.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${result1.uniquenGenusNameList2.length}`,
            `${getProportionValue(result1.uniquenGenusNameList2.length, totalGenusCount)}`,
            `${result1.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(result1.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "总记",
            `${totalFamilyCount}`,
            `100`,
            `${totalGenusCount}`,
            `100`,
            `${totalSpeciesCount}`,
            `100`,
        ])
    }
    let paragraph: ReportParagraphBlock = {
        type: "Table",
        text: "表格",
        tableData: tableData,
        colSpanInfoList: colSpanInfoList,
        rowSpanInfoList: rowSpanInfoList,
        tableHeaderRowNumber: 1,
        tableStyle: 'normalTable',
    }
    return paragraph;
}

const caculateProtectionAnimalCategoryLevelProportionTable = (
    speciesStatistics: Record<string, CategoryWithChildren>
): ReportParagraphBlock => {
    let colSpanInfoList: ColSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 2,
            colSpan: 2,
        },
        {
            rowIndex: 0,
            colIndex: 4,
            colSpan: 2,
        },
        {
            rowIndex: 0,
            colIndex: 6,
            colSpan: 2,
        },
    ];
    let rowSpanInfoList: RowSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 0,
            rowSpan: 2,
        },
        {
            rowIndex: 0,
            colIndex: 1,
            rowSpan: 2,
        },
    ];
    let tableData: string[][] = [
        ["分类", "保护等级", "科", "", "属", "", "种", ""],
        ["", "", "数量", "占比%", "数量", "占比%", "数量", "占比%"],
    ];
    let rowSpanStartRowIndex = 2;
    const totalMammalOrderCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['兽类'], 'order');
    const totalMammalFamilyCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['兽类'], 'family');
    const totalMammalSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['兽类'], 'species');
    //
    const totalBirdOrderCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['鸟类'], 'order');
    const totalBirdFamilyCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['鸟类'], 'family');
    const totalBirdSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['鸟类'], 'species');
    //
    const totalCrawlOrderCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['两爬类'], 'order');
    const totalCrawlFamilyCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['两爬类'], 'family');
    const totalCrawlSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['两爬类'], 'species');
    //
    const totalInsectOrderCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['昆虫'], 'order');
    const totalInsectFamilyCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['昆虫'], 'family');
    const totalInsectSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['昆虫'], 'species');
    //
    const totalFishOrderCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['鱼类'], 'order');
    const totalFishFamilyCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['鱼类'], 'family');
    const totalFishSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['鱼类'], 'species');
    //兽类
    const mammalResult = extractNationalProtectionSpeciesStatisticsTotalCategory(speciesStatistics['兽类']);
    //鸟类
    const birdResult = extractNationalProtectionSpeciesStatisticsTotalCategory(speciesStatistics['鸟类']);
    //两爬类
    const crawlResult = extractNationalProtectionSpeciesStatisticsTotalCategory(speciesStatistics['两爬类']);
    //昆虫
    const insectResult = extractNationalProtectionSpeciesStatisticsTotalCategory(speciesStatistics['昆虫']);
    //鱼类
    const fishResult = extractNationalProtectionSpeciesStatisticsTotalCategory(speciesStatistics['鱼类']);
    //总物种数量
    const totalSpeciesCount =
        mammalResult.uniquenSpeciesNameList1.length + mammalResult.uniquenSpeciesNameList2.length +
        birdResult.uniquenSpeciesNameList1.length + birdResult.uniquenSpeciesNameList2.length +
        crawlResult.uniquenSpeciesNameList1.length + crawlResult.uniquenSpeciesNameList2.length +
        insectResult.uniquenSpeciesNameList1.length + insectResult.uniquenSpeciesNameList2.length +
        fishResult.uniquenSpeciesNameList1.length + fishResult.uniquenSpeciesNameList2.length
    //总科数量
    const totalGenusCount =
        mammalResult.uniquenGenusNameList1.length + mammalResult.uniquenGenusNameList2.length +
        birdResult.uniquenGenusNameList1.length + birdResult.uniquenGenusNameList2.length +
        crawlResult.uniquenGenusNameList1.length + crawlResult.uniquenGenusNameList2.length +
        insectResult.uniquenGenusNameList1.length + insectResult.uniquenGenusNameList2.length +
        fishResult.uniquenGenusNameList1.length + fishResult.uniquenGenusNameList2.length
    //
    const totalFamilyCount =
        mammalResult.uniquenFamilyNameList1.length + mammalResult.uniquenFamilyNameList2.length +
        birdResult.uniquenFamilyNameList1.length + birdResult.uniquenFamilyNameList2.length +
        crawlResult.uniquenFamilyNameList1.length + crawlResult.uniquenFamilyNameList2.length +
        insectResult.uniquenFamilyNameList1.length + insectResult.uniquenFamilyNameList2.length +
        fishResult.uniquenFamilyNameList1.length + fishResult.uniquenFamilyNameList2.length
    const totalOrderCount =
        mammalResult.uniquenOrderNameList1.length + mammalResult.uniquenOrderNameList2.length +
        birdResult.uniquenOrderNameList1.length + birdResult.uniquenOrderNameList2.length +
        crawlResult.uniquenOrderNameList1.length + crawlResult.uniquenOrderNameList2.length +
        insectResult.uniquenOrderNameList1.length + insectResult.uniquenOrderNameList2.length +
        fishResult.uniquenOrderNameList1.length + fishResult.uniquenOrderNameList2.length
    //
    if (speciesStatistics['兽类']) {
        rowSpanInfoList.push({
            rowIndex: rowSpanStartRowIndex,
            colIndex: 0,
            rowSpan: 3,
        })
        tableData.push([
            "兽类",
            "国家I级",
            `${mammalResult.uniquenFamilyNameList1.length}`,
            `${getProportionValue(mammalResult.uniquenFamilyNameList1.length, totalFamilyCount)}`,
            `${mammalResult.uniquenGenusNameList1.length}`,
            `${getProportionValue(mammalResult.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${mammalResult.uniquenSpeciesNameList1.length}`,
            `${getProportionValue(mammalResult.uniquenSpeciesNameList1.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "国家II级",
            `${mammalResult.uniquenFamilyNameList2.length}`,
            `${getProportionValue(mammalResult.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${mammalResult.uniquenGenusNameList2.length}`,
            `${getProportionValue(mammalResult.uniquenGenusNameList2.length, totalGenusCount)}`,
            `${mammalResult.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(mammalResult.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "小记",
            `${mammalResult.uniquenFamilyNameList1.length + mammalResult.uniquenFamilyNameList2.length}`,
            `${getProportionValue(mammalResult.uniquenFamilyNameList1.length + mammalResult.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${mammalResult.uniquenGenusNameList1.length + mammalResult.uniquenGenusNameList2.length}`,
            `${getProportionValue(mammalResult.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${mammalResult.uniquenSpeciesNameList1.length + mammalResult.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(mammalResult.uniquenSpeciesNameList1.length + mammalResult.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        rowSpanStartRowIndex += 3;
    }
    //
    if (speciesStatistics['鸟类']) {
        rowSpanInfoList.push({
            rowIndex: rowSpanStartRowIndex,
            colIndex: 0,
            rowSpan: 3,
        })
        tableData.push([
            "鸟类",
            "国家I级",
            `${birdResult.uniquenFamilyNameList1.length}`,
            `${getProportionValue(birdResult.uniquenFamilyNameList1.length, totalFamilyCount)}`,
            `${birdResult.uniquenGenusNameList1.length}`,
            `${getProportionValue(birdResult.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${birdResult.uniquenSpeciesNameList1.length}`,
            `${getProportionValue(birdResult.uniquenSpeciesNameList1.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "国家II级",
            `${birdResult.uniquenFamilyNameList2.length}`,
            `${getProportionValue(birdResult.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${birdResult.uniquenGenusNameList2.length}`,
            `${getProportionValue(birdResult.uniquenGenusNameList2.length, totalGenusCount)}`,
            `${birdResult.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(birdResult.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "小记",
            `${birdResult.uniquenFamilyNameList1.length + birdResult.uniquenFamilyNameList2.length}`,
            `${getProportionValue(birdResult.uniquenFamilyNameList1.length + birdResult.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${birdResult.uniquenGenusNameList1.length + birdResult.uniquenGenusNameList2.length}`,
            `${getProportionValue(birdResult.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${birdResult.uniquenSpeciesNameList1.length + birdResult.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(birdResult.uniquenSpeciesNameList1.length + birdResult.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        rowSpanStartRowIndex += 3;
    }
    //
    if (speciesStatistics['两爬类']) {
        rowSpanInfoList.push({
            rowIndex: rowSpanStartRowIndex,
            colIndex: 0,
            rowSpan: 3,
        })
        tableData.push([
            "两爬类",
            "国家I级",
            `${crawlResult.uniquenFamilyNameList1.length}`,
            `${getProportionValue(crawlResult.uniquenFamilyNameList1.length, totalFamilyCount)}`,
            `${crawlResult.uniquenGenusNameList1.length}`,
            `${getProportionValue(crawlResult.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${crawlResult.uniquenSpeciesNameList1.length}`,
            `${getProportionValue(crawlResult.uniquenSpeciesNameList1.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "国家II级",
            `${crawlResult.uniquenFamilyNameList2.length}`,
            `${getProportionValue(crawlResult.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${crawlResult.uniquenGenusNameList2.length}`,
            `${getProportionValue(crawlResult.uniquenGenusNameList2.length, totalGenusCount)}`,
            `${crawlResult.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(crawlResult.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "小记",
            `${crawlResult.uniquenFamilyNameList1.length + crawlResult.uniquenFamilyNameList2.length}`,
            `${getProportionValue(crawlResult.uniquenFamilyNameList1.length + crawlResult.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${crawlResult.uniquenGenusNameList1.length + crawlResult.uniquenGenusNameList2.length}`,
            `${getProportionValue(crawlResult.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${crawlResult.uniquenSpeciesNameList1.length + crawlResult.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(crawlResult.uniquenSpeciesNameList1.length + crawlResult.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        rowSpanStartRowIndex += 3;
    }
    if (speciesStatistics['昆虫']) {
        rowSpanInfoList.push({
            rowIndex: rowSpanStartRowIndex,
            colIndex: 0,
            rowSpan: 3,
        })
        tableData.push([
            "昆虫",
            "国家I级",
            `${insectResult.uniquenFamilyNameList1.length}`,
            `${getProportionValue(insectResult.uniquenFamilyNameList1.length, totalFamilyCount)}`,
            `${insectResult.uniquenGenusNameList1.length}`,
            `${getProportionValue(insectResult.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${insectResult.uniquenSpeciesNameList1.length}`,
            `${getProportionValue(insectResult.uniquenSpeciesNameList1.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "国家II级",
            `${insectResult.uniquenFamilyNameList2.length}`,
            `${getProportionValue(insectResult.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${insectResult.uniquenGenusNameList2.length}`,
            `${getProportionValue(insectResult.uniquenGenusNameList2.length, totalGenusCount)}`,
            `${insectResult.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(insectResult.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "小记",
            `${insectResult.uniquenFamilyNameList1.length + insectResult.uniquenFamilyNameList2.length}`,
            `${getProportionValue(insectResult.uniquenFamilyNameList1.length + insectResult.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${insectResult.uniquenGenusNameList1.length + insectResult.uniquenGenusNameList2.length}`,
            `${getProportionValue(insectResult.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${insectResult.uniquenSpeciesNameList1.length + insectResult.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(insectResult.uniquenSpeciesNameList1.length + insectResult.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        rowSpanStartRowIndex += 3;
    }
    if (speciesStatistics['鱼类']) {
        rowSpanInfoList.push({
            rowIndex: rowSpanStartRowIndex,
            colIndex: 0,
            rowSpan: 3,
        })
        tableData.push([
            "鱼类",
            "国家I级",
            `${fishResult.uniquenFamilyNameList1.length}`,
            `${getProportionValue(fishResult.uniquenFamilyNameList1.length, totalFamilyCount)}`,
            `${fishResult.uniquenGenusNameList1.length}`,
            `${getProportionValue(fishResult.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${fishResult.uniquenSpeciesNameList1.length}`,
            `${getProportionValue(fishResult.uniquenSpeciesNameList1.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "国家II级",
            `${fishResult.uniquenFamilyNameList2.length}`,
            `${getProportionValue(fishResult.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${fishResult.uniquenGenusNameList2.length}`,
            `${getProportionValue(fishResult.uniquenGenusNameList2.length, totalGenusCount)}`,
            `${fishResult.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(fishResult.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        tableData.push([
            "",
            "小记",
            `${fishResult.uniquenFamilyNameList1.length + fishResult.uniquenFamilyNameList2.length}`,
            `${getProportionValue(fishResult.uniquenFamilyNameList1.length + fishResult.uniquenFamilyNameList2.length, totalFamilyCount)}`,
            `${fishResult.uniquenGenusNameList1.length + fishResult.uniquenGenusNameList2.length}`,
            `${getProportionValue(fishResult.uniquenGenusNameList1.length, totalGenusCount)}`,
            `${fishResult.uniquenSpeciesNameList1.length + fishResult.uniquenSpeciesNameList2.length}`,
            `${getProportionValue(fishResult.uniquenSpeciesNameList1.length + fishResult.uniquenSpeciesNameList2.length, totalSpeciesCount)}`,
        ])
        rowSpanStartRowIndex += 3;
    }
    tableData.push([
        "总记",
        "总记",
        `${totalFamilyCount}`,
        `100`,
        `${totalGenusCount}`,
        `100`,
        `${totalSpeciesCount}`,
        `100`,
    ])
    colSpanInfoList.push({
        rowIndex: tableData.length - 1,
        colIndex: 0,
        colSpan: 2,
    })
    let paragraph: ReportParagraphBlock = {
        type: "Table",
        text: "表格",
        tableData: tableData,
        colSpanInfoList: colSpanInfoList,
        rowSpanInfoList: rowSpanInfoList,
        tableHeaderRowNumber: 1,
    }
    return paragraph;
}

//植物科属种统计
const caculatePlantFamilyGenusSpeciesProportionTable = (
    speciesStatistics: Record<string, CategoryWithChildren>
): TableGenerateResult => {
    let tableResult: TableGenerateResult = {
        tableStyle: 'normalTable',
        tableHeaderRowNumber: 2,
    }
    let tableData: string[][] = [
        ["分类", "科", "", "属", "", "种", ""],
        ["", "数量", "占比%", "数量", "占比%", "数量", "占比%"]
    ];
    const totalBeiziFamilyCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['被子植物'], 'family');
    const totalBeiziGenusCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['被子植物'], 'genus');
    const totalBeiziSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['被子植物'], 'species');
    //
    const totalLuoziFamilyCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['裸子植物'], 'family');
    const totalLuoziGenusCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['裸子植物'], 'genus');
    const totalLuoziSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['裸子植物'], 'species');
    //
    const totalJueleiFamilyCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['蕨类植物'], 'family');
    const totalJueleiGenusCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['蕨类植物'], 'genus');
    const totalJueleiSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['蕨类植物'], 'species');
    //
    const totalFamilyCount = totalBeiziFamilyCount + totalLuoziFamilyCount + totalJueleiFamilyCount;
    const totalGenusCount = totalBeiziGenusCount + totalLuoziGenusCount + totalJueleiGenusCount;
    const totalSpeciesCount = totalBeiziSpeciesCount + totalLuoziSpeciesCount + totalJueleiSpeciesCount;
    if (speciesStatistics['被子植物']) {
        let tableRowData = [
            "被子植物",
            totalBeiziFamilyCount.toString(),
            getProportionValue(totalBeiziFamilyCount, totalFamilyCount),
            totalBeiziGenusCount.toString(),
            getProportionValue(totalBeiziGenusCount, totalGenusCount),
            totalSpeciesCount.toString(),
            getProportionValue(totalBeiziSpeciesCount, totalSpeciesCount)
        ];
        tableData.push(tableRowData);
    }
    if (speciesStatistics['裸子植物']) {
        let tableRowData = [
            "裸子植物",
            totalLuoziFamilyCount.toString(),
            getProportionValue(totalLuoziFamilyCount, totalFamilyCount),
            totalLuoziGenusCount.toString(),
            getProportionValue(totalLuoziGenusCount, totalGenusCount),
            totalLuoziSpeciesCount.toString(),
            getProportionValue(totalLuoziSpeciesCount, totalSpeciesCount)
        ];
        tableData.push(tableRowData);
    }
    if (speciesStatistics['蕨类植物']) {
        let tableRowData = [
            "蕨类植物",
            totalJueleiFamilyCount.toString(),
            getProportionValue(totalJueleiFamilyCount, totalFamilyCount),
            totalJueleiGenusCount.toString(),
            getProportionValue(totalJueleiGenusCount, totalGenusCount),
            totalJueleiSpeciesCount.toString(),
            getProportionValue(totalJueleiSpeciesCount, totalSpeciesCount)
        ];
        tableData.push(tableRowData);
    }
    let tableRowSpanInfoList: RowSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 0,
            rowSpan: 2
        }
    ];
    let tableColSpanInfoList: ColSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 1,
            colSpan: 2
        },
        {
            rowIndex: 0,
            colIndex: 3,
            colSpan: 2
        },
        {
            rowIndex: 0,
            colIndex: 5,
            colSpan: 2
        },
    ];
    tableData.push(["总计", totalFamilyCount.toString(), "100", totalGenusCount.toString(), "100", totalSpeciesCount.toString(), "100"]);
    tableResult.tableData = tableData;
    tableResult.tableRowSpanInfoList = tableRowSpanInfoList;
    tableResult.tableColSpanInfoList = tableColSpanInfoList;
    tableResult.tableStyle = 'normalTable';
    return tableResult;
}

const caculateAnimalOrderFamilySpeciesTotalProportionTable = (
    speciesStatistics: Record<string, CategoryWithChildren>
): TableGenerateResult => {
    let tableResult: TableGenerateResult = {
        tableStyle: 'normalTable',
        tableHeaderRowNumber: 2,
    }
    let tableData: string[][] = [
        ["分类", "目", "", "属", "", "种", ""],
        ["", "数量", "占比%", "数量", "占比%", "数量", "占比%"]
    ];
    // speciesStatistics["兽类"] ||
    //     speciesStatistics["鸟类"] ||
    //     speciesStatistics["两爬类"] ||
    //     speciesStatistics["昆虫"] ||
    //     speciesStatistics["鱼类"]
    const totalMammalOrderCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['兽类'], 'order');
    const totalMammalFamilyCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['兽类'], 'family');
    const totalMammalSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['兽类'], 'species');
    //
    const totalBirdOrderCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['鸟类'], 'order');
    const totalBirdFamilyCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['鸟类'], 'family');
    const totalBirdSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['鸟类'], 'species');
    //
    const totalCrawlOrderCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['两爬类'], 'order');
    const totalCrawlFamilyCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['两爬类'], 'family');
    const totalCrawlSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['两爬类'], 'species');
    //
    const totalInsectOrderCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['昆虫'], 'order');
    const totalInsectFamilyCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['昆虫'], 'family');
    const totalInsectSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['昆虫'], 'species');
    //
    const totalFishOrderCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['鱼类'], 'order');
    const totalFishFamilyCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['鱼类'], 'family');
    const totalFishSpeciesCount = extractSpeciesStatisticsTotalCategory(speciesStatistics['鱼类'], 'species');
    //
    const totalOrderCount =
        totalMammalOrderCount + totalBirdOrderCount + totalCrawlOrderCount + totalInsectOrderCount + totalFishOrderCount;
    const totalFamilyCount =
        totalMammalFamilyCount + totalBirdFamilyCount + totalCrawlFamilyCount + totalInsectFamilyCount + totalFishFamilyCount;
    const totalSpeciesCount =
        totalMammalSpeciesCount + totalBirdSpeciesCount + totalCrawlSpeciesCount + totalInsectSpeciesCount + totalFishSpeciesCount;
    if (speciesStatistics['兽类']) {
        let tableRowData = [
            "兽类",
            totalMammalOrderCount.toString(),
            getProportionValue(totalMammalOrderCount, totalOrderCount),
            totalMammalFamilyCount.toString(),
            getProportionValue(totalMammalFamilyCount, totalFamilyCount),
            totalMammalSpeciesCount.toString(),
            getProportionValue(totalMammalSpeciesCount, totalSpeciesCount)
        ];
        tableData.push(tableRowData);
    }
    if (speciesStatistics['鸟类']) {
        let tableRowData = [
            "鸟类",
            totalBirdOrderCount.toString(),
            getProportionValue(totalBirdOrderCount, totalOrderCount),
            totalBirdFamilyCount.toString(),
            getProportionValue(totalBirdFamilyCount, totalFamilyCount),
            totalBirdSpeciesCount.toString(),
            getProportionValue(totalBirdSpeciesCount, totalSpeciesCount)
        ];
        tableData.push(tableRowData);
    }
    if (speciesStatistics['两爬类']) {
        let tableRowData = [
            "两爬类",
            totalCrawlOrderCount.toString(),
            getProportionValue(totalCrawlOrderCount, totalOrderCount),
            totalCrawlFamilyCount.toString(),
            getProportionValue(totalCrawlFamilyCount, totalFamilyCount),
            totalCrawlSpeciesCount.toString(),
            getProportionValue(totalCrawlSpeciesCount, totalSpeciesCount)
        ];
        tableData.push(tableRowData);
    }
    if (speciesStatistics['昆虫']) {
        let tableRowData = [
            "昆虫",
            totalInsectOrderCount.toString(),
            getProportionValue(totalInsectOrderCount, totalOrderCount),
            totalInsectFamilyCount.toString(),
            getProportionValue(totalInsectFamilyCount, totalFamilyCount),
            totalInsectSpeciesCount.toString(),
            getProportionValue(totalInsectSpeciesCount, totalSpeciesCount)
        ];
        tableData.push(tableRowData);
    }
    if (speciesStatistics['鱼类']) {
        let tableRowData = [
            "鱼类",
            totalFishOrderCount.toString(),
            getProportionValue(totalFishOrderCount, totalOrderCount),
            totalFishFamilyCount.toString(),
            getProportionValue(totalFishFamilyCount, totalFamilyCount),
            totalFishSpeciesCount.toString(),
            getProportionValue(totalFishSpeciesCount, totalSpeciesCount)
        ];
        tableData.push(tableRowData);
    }
    tableData.push([
        "总计",
        totalOrderCount.toString(),
        "100",
        totalFamilyCount.toString(),
        "100",
        totalSpeciesCount.toString(),
        "100"
    ]);
    let tableRowSpanInfoList: RowSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 0,
            rowSpan: 2
        }
    ];
    let tableColSpanInfoList: ColSpanInfo[] = [
        {
            rowIndex: 0,
            colIndex: 1,
            colSpan: 2
        },
        {
            rowIndex: 0,
            colIndex: 3,
            colSpan: 2
        },
        {
            rowIndex: 0,
            colIndex: 5,
            colSpan: 2
        },
    ];
    tableResult.tableData = tableData;
    tableResult.tableRowSpanInfoList = tableRowSpanInfoList;
    tableResult.tableColSpanInfoList = tableColSpanInfoList;
    tableResult.tableStyle = 'normalTable';
    console.log("tableResult--->", tableResult)
    return tableResult;
}

//动物目科种统计
const caculateAnimalOrderFamilySpeciesProportionTable = (
    categoryWithChildren: CategoryWithChildren
): TableGenerateResult => {
    let tableResult: TableGenerateResult = {
        tableStyle: 'normalTable',
        tableHeaderRowNumber: 2,
        tableRowSpanInfoList: [
            {
                rowIndex: 0,
                colIndex: 0,
                rowSpan: 2,
            },
            {
                rowIndex: 0,
                colIndex: 1,
                rowSpan: 2,
            }
        ],
        tableColSpanInfoList: [
            {
                rowIndex: 0,
                colIndex: 2,
                colSpan: 2
            }
        ]
    }
    // let tableData: string[][] = [
    //     ["分类", "目", "", "科", "", "种", ""],
    //     ["", "数量", "占比%", "数量", "占比%", "数量", "占比%"]
    // ];
    let tableData: string[][] = [
        ["目", "科", "种", ""],
        ["", "", "数量", "占比%"],
    ];
    const totalOrderCount = extractSpeciesStatisticsTotalCategory(categoryWithChildren, 'order');
    const totalFamilyCount = extractSpeciesStatisticsTotalCategory(categoryWithChildren, 'genus');
    const totalSpeciesCount = extractSpeciesStatisticsTotalCategory(categoryWithChildren, 'species');
    for (const orderKey in categoryWithChildren) {
        const orderRecord = categoryWithChildren[orderKey].children;
        const orderLatin = categoryWithChildren[orderKey].latin;
        for (const familyKey in orderRecord) {
            let totalGenusCountForTheFamily = 0;
            let totalSpeciesCountForTheFamily = 0;
            const familyRecord = orderRecord[familyKey].children;
            const familyLatin = orderRecord[familyKey].latin;
            for (const genusKey in familyRecord) {
                totalGenusCountForTheFamily++;
                const genusRecord = familyRecord[genusKey].children;
                for (const speciesKey in genusRecord) {
                    totalSpeciesCountForTheFamily++;
                }
            }
            let tempTableRow = [
                `${orderKey} ${orderLatin}`,
                `${familyKey} ${familyLatin}`,
                totalSpeciesCountForTheFamily.toString(),
                getProportionValue(totalSpeciesCountForTheFamily, totalSpeciesCount)
            ];
            tableData.push(tempTableRow);
        }
    }
    tableResult.tableData = tableData;
    return tableResult;
}


const createSpeciesStatisticsReport = ({
    mergedRowDataList
}: CreateSpeciesStatisticsParams): ReportGenerateResult => {
    try {
        let reportGenerateResult: ReportGenerateResult = {
            reportParagraphList: [],
            matchFailureParagraphList: []
        };
        let reportParagraphList: ReportParagraphBlock[] = [];
        let matchFailureParagraphList: ReportParagraphBlock[] = [];
        const speciesStatistics: Record<string, CategoryWithChildren> = generateSpeciesStatistics(mergedRowDataList);
        console.log("speciesStatistics--->", speciesStatistics)
        let serialNumberOfBigType = 1;
        let serialNumberOfSubType = 1;
        let serialNumberOfBigTypeTable = 1;
        if (
            speciesStatistics["被子植物"] ||
            speciesStatistics["裸子植物"] ||
            speciesStatistics["蕨类植物"]
        ) {
            reportParagraphList.push(generateWordParagraBlockByPlainText('物种统计', 'heading1'));
            reportParagraphList.push(generateWordParagraBlockByPlainText(`${serialNumberOfBigType}.植物统计`, 'heading2'));
            reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
            reportParagraphList.push(generateWordParagraBlockByPlainText(`表植物科属种统计`, 'smallTableName'));
            const plantFamilyGenusSpeciesProportionTable = caculatePlantFamilyGenusSpeciesProportionTable(speciesStatistics);
            reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(plantFamilyGenusSpeciesProportionTable))
            serialNumberOfBigTypeTable++;
            if (speciesStatistics["被子植物"]) {
                //科属种占比
                reportParagraphList.push(generateWordParagraBlockByPlainText(`${serialNumberOfBigType}.${serialNumberOfSubType}被子植物统计`, 'heading4'));
                reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表被子植物各科统计`, 'smallTableName'));
                const beiziFamilyProportionTable = caculateCategoryFamilyProportionTable(speciesStatistics["被子植物"]);
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziFamilyProportionTable));
                serialNumberOfBigTypeTable++;
                //科、属结构占比
                reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表 被子植物科及属的数量结构`, 'smallTableName'));
                const beiziFamilyAndGenusStructureTable = caculateCategoryFamilyAndGenusQuantitativeStructure(speciesStatistics["被子植物"]);
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziFamilyAndGenusStructureTable));
                serialNumberOfBigTypeTable++;
                //科、种结构占比
                reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                // ${serialNumberOfBigType} - ${serialNumberOfBigTypeTable}
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表 被子植物科及种的数量结构`, 'smallTableName'));
                const beiziFamilyAndSpeciesStructureTable = caculateCategoryFamilyAndSpeciesQuantitativeStructure(speciesStatistics["被子植物"]);
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziFamilyAndSpeciesStructureTable));
                serialNumberOfBigTypeTable++;
                //各属统计
                reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表 被子植物各属统计`, 'smallTableName'));
                const beiziGenusProportionTable = caculateCategoryGenusProportionTable(speciesStatistics["被子植物"]);
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziGenusProportionTable));
                serialNumberOfBigTypeTable++;
                //属及种数量结构
                reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表 被子植物属及种数量结构`, 'smallTableName'));
                const beiziGenusAndSpeciesQuantitativeStructureTable = caculateCategoryGenusAndSpeciesQuantitativeStructure(speciesStatistics["被子植物"]);
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziGenusAndSpeciesQuantitativeStructureTable));
                serialNumberOfSubType++;
                serialNumberOfBigTypeTable++;
                //重置
                // serialNumberOfBigType++;
                // serialNumberOfBigTypeTable = 1;
            }
            if (speciesStatistics["裸子植物"]) {
                //科属种占比
                reportParagraphList.push(generateWordParagraBlockByPlainText(`${serialNumberOfBigType}.${serialNumberOfSubType}裸子植物统计`, 'heading4'));
                reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表裸子植物各科统计`, 'smallTableName'));
                const beiziFamilyProportionTable = caculateCategoryFamilyProportionTable(speciesStatistics["裸子植物"]);
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziFamilyProportionTable));
                serialNumberOfBigTypeTable++;
                //科、属结构占比
                reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表 裸子植物科及属的数量结构`, 'smallTableName'));
                const beiziFamilyAndGenusStructureTable = caculateCategoryFamilyAndGenusQuantitativeStructure(speciesStatistics["裸子植物"]);
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziFamilyAndGenusStructureTable));
                serialNumberOfBigTypeTable++;
                //科、种结构占比
                reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表 裸子植物科及种的数量结构`, 'smallTableName'));
                const beiziFamilyAndSpeciesStructureTable = caculateCategoryFamilyAndSpeciesQuantitativeStructure(speciesStatistics["裸子植物"]);
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziFamilyAndSpeciesStructureTable));
                serialNumberOfBigTypeTable++;
                //各属统计
                reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表 裸子植物各属统计`, 'smallTableName'));
                const beiziGenusProportionTable = caculateCategoryGenusProportionTable(speciesStatistics["裸子植物"]);
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziGenusProportionTable));
                serialNumberOfBigTypeTable++;
                //属及种数量结构
                reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表 裸子植物属及种数量结构`, 'smallTableName'));
                const beiziGenusAndSpeciesQuantitativeStructureTable = caculateCategoryGenusAndSpeciesQuantitativeStructure(speciesStatistics["裸子植物"]);
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziGenusAndSpeciesQuantitativeStructureTable));
                serialNumberOfSubType++;
                serialNumberOfBigTypeTable++;
                //重置
                // serialNumberOfBigType++;
                // serialNumberOfBigTypeTable = 1;
            }
            if (speciesStatistics["蕨类植物"]) {
                //科属种占比
                reportParagraphList.push(generateWordParagraBlockByPlainText(`${serialNumberOfBigType}.${serialNumberOfSubType}蕨类植物统计`, 'heading4'));
                reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表蕨类植物各科统计`, 'smallTableName'));
                const beiziFamilyProportionTable = caculateCategoryFamilyProportionTable(speciesStatistics["蕨类植物"]);
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziFamilyProportionTable));
                serialNumberOfBigTypeTable++;
                //科、属结构占比
                reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表 蕨类植物科及属的数量结构`, 'smallTableName'));
                const beiziFamilyAndGenusStructureTable = caculateCategoryFamilyAndGenusQuantitativeStructure(speciesStatistics["蕨类植物"]);
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziFamilyAndGenusStructureTable));
                serialNumberOfBigTypeTable++;
                //科、种结构占比
                reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表 蕨类植物科及种的数量结构`, 'smallTableName'));
                const beiziFamilyAndSpeciesStructureTable = caculateCategoryFamilyAndSpeciesQuantitativeStructure(speciesStatistics["蕨类植物"]);
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziFamilyAndSpeciesStructureTable));
                serialNumberOfBigTypeTable++;
                //各属统计
                reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表 蕨类植物各属统计`, 'smallTableName'));
                const beiziGenusProportionTable = caculateCategoryGenusProportionTable(speciesStatistics["蕨类植物"]);
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziGenusProportionTable));
                serialNumberOfBigTypeTable++;
                //属及种数量结构
                reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表 蕨类植物属及种数量结构`, 'smallTableName'));
                const beiziGenusAndSpeciesQuantitativeStructureTable = caculateCategoryGenusAndSpeciesQuantitativeStructure(speciesStatistics["蕨类植物"]);
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziGenusAndSpeciesQuantitativeStructureTable));
                serialNumberOfSubType++;
                serialNumberOfBigTypeTable++;
            }
            // console.log("speciesStatistics--->", speciesStatistics)
            reportParagraphList.push(generateWordParagraBlockByPlainText(`${serialNumberOfBigType}.${serialNumberOfSubType}保护植物统计`, 'heading4'));
            reportParagraphList.push(generateWordParagraBlockByPlainText(`表国家保护植物统计`, 'smallTableName'));
            const protectionPlantCategoryLevelProportionTableParagraph = caculateProtectionPlantCategoryLevelProportionTable(speciesStatistics["被子植物"], speciesStatistics["裸子植物"], speciesStatistics["蕨类植物"]);
            reportParagraphList.push(protectionPlantCategoryLevelProportionTableParagraph)
            serialNumberOfBigType++;
        }
        if (speciesStatistics["大型真菌"]) {
            reportParagraphList.push(generateWordParagraBlockByPlainText(`${serialNumberOfBigType}.大型真菌统计`, 'heading2'));
            //科属种占比
            // reportParagraphList.push(generateWordParagraBlockByPlainText(`${serialNumberOfBigType}.${serialNumberOfSubType}裸子植物统计`, 'heading4'));
            reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
            reportParagraphList.push(generateWordParagraBlockByPlainText(`表大型真菌各科统计`, 'smallTableName'));
            const beiziFamilyProportionTable = caculateCategoryFamilyProportionTable(speciesStatistics["裸子植物"]);
            reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziFamilyProportionTable));
            serialNumberOfBigTypeTable++;
            //科、属结构占比
            reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
            reportParagraphList.push(generateWordParagraBlockByPlainText(`表 大型真菌科及属的数量结构`, 'smallTableName'));
            const beiziFamilyAndGenusStructureTable = caculateCategoryFamilyAndGenusQuantitativeStructure(speciesStatistics["大型真菌"]);
            reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziFamilyAndGenusStructureTable));
            serialNumberOfBigTypeTable++;
            //科、种结构占比
            reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
            reportParagraphList.push(generateWordParagraBlockByPlainText(`表 大型真菌科及种的数量结构`, 'smallTableName'));
            const beiziFamilyAndSpeciesStructureTable = caculateCategoryFamilyAndSpeciesQuantitativeStructure(speciesStatistics["大型真菌"]);
            reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziFamilyAndSpeciesStructureTable));
            serialNumberOfBigTypeTable++;
            //各属统计
            reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
            reportParagraphList.push(generateWordParagraBlockByPlainText(`表 大型真菌各属统计`, 'smallTableName'));
            const beiziGenusProportionTable = caculateCategoryGenusProportionTable(speciesStatistics["大型真菌"]);
            reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziGenusProportionTable));
            serialNumberOfBigTypeTable++;
            //属及种数量结构
            reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
            reportParagraphList.push(generateWordParagraBlockByPlainText(`表 大型真菌属及种数量结构`, 'smallTableName'));
            const beiziGenusAndSpeciesQuantitativeStructureTable = caculateCategoryGenusAndSpeciesQuantitativeStructure(speciesStatistics["大型真菌"]);
            reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(beiziGenusAndSpeciesQuantitativeStructureTable));
            serialNumberOfSubType++;
            serialNumberOfBigTypeTable++;
            reportParagraphList.push(generateWordParagraBlockByPlainText(`表国家保护大型真菌统计`, 'smallTableName'));
            const protectionPlantCategoryLevelProportionTableParagraph = caculateProtectionFungusCategoryLevelCountTable(speciesStatistics["大型真菌"]);
            reportParagraphList.push(protectionPlantCategoryLevelProportionTableParagraph)
            serialNumberOfBigType++;
        }
        let animalTypes = ["兽类", "鸟类", "两爬类", "昆虫", "鱼类"]
        if (
            speciesStatistics["兽类"] ||
            speciesStatistics["鸟类"] ||
            speciesStatistics["两爬类"] ||
            speciesStatistics["昆虫"] ||
            speciesStatistics["鱼类"]
        ) {
            // 3.动物统计
            reportParagraphList.push(generateWordParagraBlockByPlainText(`${serialNumberOfBigType}.动物统计`, 'heading2'));
            serialNumberOfBigTypeTable = 1;
            //动物目科种统计
            reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
            reportParagraphList.push(generateWordParagraBlockByPlainText(`表动物目科种统计`, 'smallTableName'));
            const animalOrderProportionTotalTable = caculateAnimalOrderFamilySpeciesTotalProportionTable(speciesStatistics);
            reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(animalOrderProportionTotalTable));
            serialNumberOfBigTypeTable++;
            animalTypes.forEach(animalType => {
                if (speciesStatistics[animalType]) {
                    //
                    //鱼类各目统计
                    reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                    reportParagraphList.push(generateWordParagraBlockByPlainText(`表${animalType}各目统计`, 'smallTableName'));
                    const animalOrderProportionTable = caculateAnimalOrderFamilySpeciesProportionTable(speciesStatistics[animalType]);
                    reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(animalOrderProportionTable));
                    serialNumberOfBigTypeTable++;
                    //鱼类各科及种的数量结构
                    reportParagraphList.push(generateWordParagraBlockByPlainText('', 'smallTableName'));
                    reportParagraphList.push(generateWordParagraBlockByPlainText(`表${animalType}各科统计`, 'smallTableName'));
                    const animalFamilyProportionTable = caculateCategoryFamilyProportionTable(speciesStatistics[animalType]);
                    reportParagraphList.push(generateWordParagraBlockByTableGenerateResult(animalFamilyProportionTable));
                    serialNumberOfBigTypeTable++;
                }
            })
            //国家保护动物统计
            reportParagraphList.push(generateWordParagraBlockByPlainText(`表国家保护动物统计`, 'smallTableName'));
            const protectionAnimalCategoryLevelProportionTableParagraph = caculateProtectionAnimalCategoryLevelProportionTable(speciesStatistics);
            reportParagraphList.push(protectionAnimalCategoryLevelProportionTableParagraph)
            serialNumberOfBigType++;
        }
        reportGenerateResult.reportParagraphList = reportParagraphList;
        reportGenerateResult.matchFailureParagraphList = matchFailureParagraphList;
        // console.log("物种统计结果---->", JSON.stringify({
        //     paragraphList: reportParagraphList
        // }))
        return reportGenerateResult;
    } catch (error) {
        console.error(error)
        //@ts-ignore
        throw new Error(error.message);
    }
}

export default createSpeciesStatisticsReport;